<!-- 评论配置 -->
<template>
    <div >
        <div class='table-page-search-wrapper'>
            <a-form :label-col="{ span: 5 }" :wrapper-col="{ span: 17 }">
                <a-form-item label="评论开关">
                    <a-switch checked-children="开启" un-checked-children="关闭" :checked="commentStatus == '1' ? true : false" @change="onChange"/>
                </a-form-item>
                <a-form-item label="点赞开关">
                    <a-switch checked-children="开启" un-checked-children="关闭" :checked="praiseStatus == '1' ? true : false" @change="onChange1"/>
                </a-form-item>
                <a-form-item v-bind="formItemLayoutWithOutLabel">
                    <a-button type="primary" @click="submit">确定</a-button>
                </a-form-item>
            </a-form>
        </div>  
    </div>
</template>

<script>
import { queryGoodsEvaluationConfig , updateGoodsEvaluationConfig } from '@/api/newMall';
export default {
    data () {
        return {
            commentStatus: '1', // 评论开关
            praiseStatus: '1', // 点赞开关
            brandId: this.global.brandId,
            id: '',
            formItemLayoutWithOutLabel: {
                wrapperCol: {
                    xs: { span: 24, offset: 0 },
                    sm: { span: 20, offset: 6 },
                },
            },
        };
    },
    created(){
        this.getData();
    },
    methods: {
        getData(){
            let _this = this;
            const params = {
                page: 0,
                size: 20,
            }
            queryGoodsEvaluationConfig(params)
            .then(res => {
                if(res.success){
                    if(res.data.content.length > 0){
                        _this.praiseStatus = res.data.content[0].praiseStatus;
                        _this.commentStatus = res.data.content[0].commentStatus;
                        _this.id = res.data.content[0].id;
                    }
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        submit(){
            let _this = this;
            const params = {
                'id': _this.id,
                'commentStatus': _this.commentStatus,
                'praiseStatus': _this.praiseStatus,
                'brandId': _this.brandId,
            }
            updateGoodsEvaluationConfig(params)
            .then(res => {
                if(res.success){
                    _this.$notification['success']({
                        message: '提示',
                        description: '修改成功',
                        duration: 8,
                    })
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        onChange(checked) {
            console.log(`a-switch to ${checked}`);
            this.commentStatus = checked ? '1' : '0'
        },
        onChange1(checked) {
            console.log(`a-switch to ${checked}`);
            this.praiseStatus = checked ? '1' : '0'
        },
    }
}

</script>
<style scoped>

</style>